package com.hy.controller;

import com.google.protobuf.ServiceException;
import com.hy.AppHttpCodeEnum;
import com.hy.Result.ResponseResult;
import com.hy.medicine.evaluation.dto.ContentCheckDTO;
import com.hy.medicine.evaluation.dto.SensitiveWordDTO;
import com.hy.service.SensitiveWordService;
import com.hy.until.CheckResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 敏感词管理
 */

@RestController
@RequestMapping("/api/sensitiveWord")
@Api(tags = "敏感词管理接口")
public class SensitiveWordController {

    @Autowired
    private SensitiveWordService sensitiveWordService;

    @PostMapping("/add")
    @ApiOperation("添加敏感词")
    public ResponseResult addWord(@RequestBody @Validated SensitiveWordDTO dto) {
        try {
            sensitiveWordService.addWord(dto.getWord(), dto.getLevel());
            return ResponseResult.okResult();
        } catch (ServiceException e) {
            return ResponseResult.errorResult(AppHttpCodeEnum.valueOf(e.getMessage()));
        }
    }

    @DeleteMapping("/{wordId}")
    @ApiOperation("删除敏感词")
    public ResponseResult deleteWord(@PathVariable Integer wordId) {
        sensitiveWordService.deleteWord(wordId);
        return ResponseResult.okResult();
    }

    @PostMapping("/check")
    @ApiOperation("检查敏感词")
    public ResponseResult checkContent(@RequestBody ContentCheckDTO dto) {
        CheckResult result = sensitiveWordService.check(dto.getContent());
        return ResponseResult.okResult(result);
    }
}



